package com.example.demo1.controller.base.company;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo1.entity.base.company.Info;
import com.example.demo1.service.base.company.InfoService;

import com.baomidou.mybatisplus.core.metadata.IPage;

@RestController("baseCompanyInfoApi")
@RequestMapping(InfoApi.PATH)
public class InfoApi {

	public final static String PATH = "/base/company/info";

	
	@Autowired
	private InfoService infoService;

	/**
	 * 初始化页面数据
	 * 
	 * @param
	 * @param request
	 * @return
	 */
	@RequestMapping("initPage")
	public String initPage(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();

		return "ok";
	}

	/**
	 * 列表查询
	 *
	 * @return
	 */
	 @RequestMapping("/list")
        @ResponseBody
        public String list(  ){
            List<Info> list=infoService.list();
		Map<String, Object> result = new HashMap<>();
		result.put("items", list);
		//result.put("total", total);
            return JSON.toJSONString(result);

        }
	
	/**
	 * 初始化编辑页面数据
	 *
	 * @return
	 */
	@RequestMapping("/initEditPage")
        @ResponseBody
        public String initEditPage(@RequestParam(value = "id",required = false) Integer id){
            Info  record=infoService.getById(id);
            if (record == null) {
            			record = new Info();
            		} else {
            		}

		Map<String, Object> result = new HashMap<>();
		result.put("entity", record);
            return JSON.toJSONString(result);

        }
	
	/**
	 * 新增或更新
	 *
	 * @return
	 */
	@RequestMapping("/save")
        @ResponseBody
        public String save(@RequestBody Info paper ){
            infoService.saveOrUpdate(paper);
            return JSON.toJSONString("ok");

        }
/**
	 * 删除
	 *
	 * @return
	 */
        @RequestMapping("/delete")
        	@ResponseBody
        	public String delete(@RequestParam(value = "id",required = false) Integer id){
        		 infoService.removeById(id);

        		Map<String, Object> result = new HashMap<>();
        		return JSON.toJSONString(result);

        	}

}
